package com.fulin.datastract.huisu;

import com.alibaba.druid.support.json.JSONUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Description 组合和,每个数可以重复使用
 * @Author fulin16
 * @Date 2020/9/30 14:07
 **/
public class CombinationSum2 {
    private static int[] condination = {5,3,1,4};
    private static int target = 6;

    public static void main(String[] args) {
        List<Integer> result = new ArrayList<Integer>();
        Arrays.sort(condination);
        combinnation(condination,6,0,result);
    }

    public static void combinnation(int[] condination,  int restVal,int start, List<Integer> result){

        if(restVal < 0 ){
            return;
        }

        if(restVal == 0){
            System.out.println(JSONUtils.toJSONString(result));
            return;
        }


        for(int i = 0; i < condination.length; i++){
            result.add(condination[i]);
            combinnation(condination, restVal - condination[i],i, result);
            result.remove(result.size() -1);
        }
    }

}
